
from typing import Any,Union

import numpy as np


def power(base:np.darray,
          exp:np.darray,
          kscope:list[int] = [0]
          ) -> np.darray:
    
    [base_t, exp_t] = np.broadcast_array(base, exp)

    r = np.abs(base_t)
    theta = np.angle(base_t)
    x = np.real(exp_t)
    y = np.imag(exp_t)

    r_res = np.power( r, x )
    a_res = y * np.log( r )


    def one(
            r:np.darray,
            a:np.darray,
            x:np.darray, 
            y:np.darray, 
            k:int) -> np.darray:

        theta = 2 * numpy.pi * k

        res_abs = r * np.exp( -y * theta )
        res_phase = a + x * theta

        res = np.empty(r, dtype=np.complex128)
        res.real = res_abs * np.cos(res_phase)
        res.imag = res_abs * np.sin(res_phase)

        return res

    return np.array([one(r_res, a_res, x, y, k) for k in kscope])



